Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frontend http client #7000

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Desvelao
Copy link
Member

@Desvelao Desvelao commented Sep 19, 2024

Description

This pull request adds a http client to the wazuh-core plugin and expose it to manage the API requests that is a composition of old services:

  • WzRequest
  • GenericRequest
  • ApiCheck
  • WzAuthentication

Moreover,

  • Components
    • TableData (generic table component based on a implementation of wazuh plugin)
    • ServerTable (based on TableWzAPI of wazuh plugin)
  • Hooks
    • useStateStorage: uses the localStorage and sessionStorage to persist the runtime data

Issues Resolved

#6959

Evidence

Test

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

- Create HTTP client based on old services
- Create HTTP client request interceptor: request
- Create HTTP client generic: GenericRequest
- Create HTTP client server: WzRequest, ApiCheck and WzAuthentication
- Enhance server API backend client
  See #6995
- Rename ILogger type to Logger
@Desvelao Desvelao self-assigned this Sep 19, 2024
Comment on lines 23 to 45
interface WzRequestServices {
request: HTTPClientRequestInterceptor['request'];
getURL(path: string): string;
getTimeout(): Promise<number>;
getServerAPI(): string;
}

interface ServerAPIResponseItems<T> {
affected_items: Array<T>;
failed_items: Array<any>;
total_affected_items: number;
total_failed_items: number;
}

interface ServerAPIResponseItemsData<T> {
data: ServerAPIResponseItems<T>;
message: string;
error: number;
}

export interface ServerAPIResponseItemsDataHTTPClient<T> {
data: ServerAPIResponseItemsData<T>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this interfaces to the types.ts file.

@Desvelao Desvelao changed the title Added frontend http client Add frontend http client Sep 27, 2024
@Desvelao Desvelao linked an issue Nov 27, 2024 that may be closed by this pull request
6 tasks
@Desvelao Desvelao marked this pull request as ready for review November 27, 2024 16:42
Copy link
Contributor

Wazuh Engine plugin code coverage (Jest) test % values
Statements 8.63% ( 64 / 741 )
Branches 7.94% ( 22 / 277 )
Functions 1.87% ( 7 / 373 )
Lines 9.1% ( 64 / 703 )

Copy link
Contributor

Wazuh Fleet plugin code coverage (Jest) test % values
Statements 4.68% ( 9 / 192 )
Branches 16.66% ( 7 / 42 )
Functions 1.11% ( 1 / 90 )
Lines 4.76% ( 9 / 189 )

Copy link
Contributor

Wazuh Check Updates plugin code coverage (Jest) test % values
Statements 76.44% ( 172 / 225 )
Branches 58.65% ( 61 / 104 )
Functions 61.7% ( 29 / 47 )
Lines 76.44% ( 172 / 225 )

Copy link
Contributor

Wazuh Core plugin code coverage (Jest) test % values
Statements 41.69% ( 710 / 1703 )
Branches 41.32% ( 417 / 1009 )
Functions 43.21% ( 239 / 553 )
Lines 42.05% ( 704 / 1674 )

Copy link
Contributor

Main plugin code coverage (Jest) test % values
Statements 13.43% ( 4027 / 29982 )
Branches 8.96% ( 1749 / 19514 )
Functions 12.98% ( 944 / 7270 )
Lines 13.6% ( 3925 / 28859 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract common services from main plugin
2 participants